//: Playground - noun: a place where people can play

import UIKit

var myString: String?

// 可选类型？
myString = "Hello, Swift!"
if myString != nil {
    print(myString)
}else{
    print("myString 值为 nil")
}

// 自动解析！
var autoWrapStr: String!
autoWrapStr = "Hello world"
if autoWrapStr != nil {
    print(autoWrapStr)
} else {
    print("字符串为nil")
}

// 可选绑定
var  autoWrapStr2:String? = nil
if let wrapStr = autoWrapStr2 {
    print(wrapStr)
} else {
    print("autoWrapStr is nil")
}

let welcomeMessage: String = "hello张玉棠"
//let oindex = welcomeMessage.index(of: "o") ?? welcomeMessage.endIndex
//let subStr = welcomeMessage[..<oindex]
//print(subStr)

let index = String.Index(encodedOffset: 5)


let name = "Marie Curie"
let firstSpace = name.index(of: " ") ?? name.endIndex
let firstName = name[..<firstSpace]
